package com.jkgl.mq;

import com.jkgl.context.RedisStreamContext;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class MessageProducer {
    private final RedisTemplate<String, String> redisTemplate;
    public RecordId sendMessage(String streamKey,String messageKey, String message) {
        Map<String, String> messageMap = new HashMap<>();
        messageMap.put(messageKey, message);
        RecordId recordId = redisTemplate.opsForStream().add(streamKey, messageMap);
        System.out.println(recordId);
        return recordId ;
    }
}